﻿<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>  VIP企业新增/修改  </title>
  <meta http-equiv="Cache-Control" content="no-cache" />
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <meta name="apple-mobile-web-app-status-bar-style" content="black">
  <meta name="apple-mobile-web-app-capable" content="yes">
  <meta name="format-detection" content="telephone=no">
  <link rel="stylesheet" href="./css/x-admin.css" media="all">
  <link rel="stylesheet" href="./css/backstage.css" media="all">
  <link rel="stylesheet" href="./js/layui/css/layui.css" media="all">
  <script src="./js/jquery.min.js"></script>
  <script src="./js/layui/layui.all.js"></script>
  <script src="js/eye.js"></script>

  <script>
      //日期控件
	  $(function(){
		   layui.use('laydate', function(){
			 var laydate = layui.laydate;
			 laydate.render({elem: '#registerTime'});
		//	 laydate.render({elem: '#vipbegin'});
		//	 laydate.render({elem: '#vipend'});
		  }); 
	  });
  
   //如果是修改,会有这个企业id存在
    var comid;
    
  	$(function(){
  		 comid=window.location.search.split("=")[1];

  		 //如进行的是修改,要把原来的信息呈现出来
  		 if(comid){
			$.ajax({
				url:"../admin/findNormaoCompanyById",
				type:"get",
				data:{comid:comid},
				dataType:"json",
				success:function(data){
					var vip=data.obj;
				
					$("#comid").val(vip.comid);
					$("#comName").val(vip.comName);
					$("#contacts").val(vip.contacts);
					$("#telephone").val(vip.telephone);
					$("#userName").val(vip.userName);
					$("#password").val(vip.password);
					$("#management").val(vip.management);
					$("#registerTime").val(vip.registerTime);
				}
			})
  		  }
  	});
 
	 
	 //验证
	 function validate(){ 
		   //先请掉所有的旧的提示信息
		    $(".msg").html("");
		    $(".comName").html("用户名不可修改");
		   
		    var result=true;
			var comName = $("#comName").val();
			var contacts = $("#contacts").val();
			var telephone = $("#telephone").val();
			var userName = $("#userName").val();
			var password = $("#password").val();	
			
			var management = $("#management").val();	
			var telephone = $("#telephone").val();	
			var registerTime = $("#registerTime").val();	
		
	
			if(comName==""){
				result=false;
				$("#comName_msg").text("企业名称不能为空")
			}
			
			if(contacts==""){
				result=false;
				$("#contacts_msg").text("联系人不能为空")
			}
			
			if(telephone==""){
				result=false;
				$("#telephone_msg").text("联系方式不能为空")
			}
			else{
				//验证手机号
				var reg = /^1(3[0-9]|4[5,7]|5[0,1,2,3,5,6,7,8,9]|6[2,5,6,7]|7[0,1,7,8,6]|8[0-9]|9[1,8,9])\d{8}$/;
				if(reg.test(telephone)==false){
					result=false;
					$("#telephone_msg").text("联系方式格式不正确");
				}
			}
			
		
		    if(management==""){
				result=false;
				$("#management_msg").text("主营项目不能为空")
			}			
		    if(userName==""){
				result=false;
				$("#userName_msg").text("用户名不能为空")
			}			
			if(password==""){
				result=false;
				$("#password_msg").text("登录密码不能为空")
			}

			else {			
				var reg=/^[0-9A-Za-z]{6,20}$/;
				if(reg.test(password)==false){
					result=false;
					$("#password_msg").text("登录密码格式不正确")
				}	
			}
			
			if(registerTime==""){
				result=false;
				$("#registerTime_msg").text("入驻日期不能为空")
			}
			
	
			return result;
	 }
	 
	 
	 function update(){
		 if(validate()==true){
			 if(confirm("确定提交更新吗?")){
			    var formData = new FormData($('#vipForm')[0]); 

		        $.ajax({
		           type: "POST",
		           url: "../admin/updateNormalcompany",  
		           data: formData,
		           processData: false,
		           contentType: false,
		           async:false,
		           success: function (data) {
		           		alert(data.message);
		           		location.href="ordinary.html"
		           }
			     });
			 }
			
			 return false
		 }
		 else{
			 alert("输入校验失败! 请按提示修正后再提交");
		 }
		 
		 return false;
	 }
	  function upToVIP(){
      	//验证
      	var vipbegin=$("#vipbegin").val();
      	var vipend=$("#vipend").val();
      	
      	var str="";
      	if(vipbegin==""){
      		str+="vip起始时间不能为空\r\n"; 
      	}
      	if(vipend==""){
      		str+="vip结束时间不能为空\r\n"
      	}
      	if(vipend<vipbegin){
      		str+="vip结束时间不能早于起始时间\r\n"
      	}

      	if(str==""){	
	        	$.ajax({
	        		url:"../admin/upgradetovip",
	   				type:"post",
	   				data:{
	   						comid:$("#comid").val(),
		   					vipbegin:$("#vipbegin").val(),
		   					vipend:$("#vipend").val()
	   					},
	   					success:function(data){
	   					alert(data.message);
	   					
	   					//关闭小窗口
	   					$("#comid").val(""),
	   					$("#vipbegin").val(""),
	   					$("#vipend").val(""),
	   					$("#div_vipdate").hide();   
	   					$("#btnUpToVip").hide();
	   				}
	        	});
      	}
      	else{
      		alert(str);
      	}
      	
      }

  </script>
</head>

<body>
 <div class="wrap">
  <div class="x-nav">
    <div class="title">
      <a id="title"><cite>普通企业修改</cite></a>
      <a href="ordinary.html" class="back">返回上页</a>
    </div>
  </div>

  <div class="x-body">
    <form class="fom" id="vipForm" name="vipForm" >
        <table class="infotable">
          <tr>        
            <td width="20%"> <label> 企业全称：  </label></td>
            <td colspan="2">
               <input type="hidden"  id="comid" name="comid" >
               <input type="text"  name="comName" id="comName" class="com_name">
               <span class="msg" id="comName_msg">*</span>
            </td>
            
          </tr>   
          
          
          <tr>
            <td><label> 主营项目：  </label></td> 
            <td>
            	<input type="text" name="management"   id="management" class="com_name">
            	<span class="msg" id="management_msg"> </span>
            </td>  
            <td>
					
			</td>          
          </tr>
                
          <tr>
            <td><label> 联系人： </label></td> 
            <td>
            	<input type="text" name="contacts"   id="contacts"  >
            	<span class="msg" id="contacts_msg"></span>
            </td>  
            <td>
				
			</td>   
          </tr>
          
            <tr>
            <td><label> 联系方式：    </label></td> 
            <td>
            	<input type="text" name="telephone"   id="telephone"  >
            	<span class="msg" id="telephone_msg">*</span>
            </td>  
            <td>
					
			</td>          
          </tr>
          
           <tr>
            <td><label> 用 户 名：    </label></td> 
            <td>
            	<input type="text" name="userName"  readonly id="userName" style="background:silver" >
         	    <span class="msg" id="userName_msg">用户名不可修改</span>
            </td>  
            <td>
					
			</td>          
          </tr>
          
          
          <tr>
            <td><label>	登录密码：   </label> </td>
            <td class="password-p">
            	<div id="div_pwd">
            	<input type="password" name="password"    id="password" > 
            	<img onclick="togglePwd('password',this)" src="images/1.png"  > 
            	<span class="msg" id="password_msg">* 6-20位字母或数字</span>
            	</div>
            </td>
            <td>
            </td>
          </tr>
          
          <tr>
            <td><label> 申请入驻时间：  </label></td> 
            <td>
            	<input   name="registerTime"   id="registerTime" >
            	<span class="msg" id="registerTime_msg">*</span>
            </td>  
            <td>
			</td>          
          </tr>
          
          <tr>
            <td></td>
            <td>
                <input type="button"  class="btn"  id="btnSubmit" value="提交"  onclick="return update()" >
            </td>
          </tr>
          
        </table>
    </form>
  </div>
</div>

    <!-- 把企业改为vip的时候弾出一个输入日期的框 ,这个功能暂时不用-->
	<div id="div_vipdate" style="display:none">
	    <input type="hidden" id="comid" >
	    <input   id="vipbegin" placeholder="vip开始日期">
	    <input   id="vipend" placeholder="vip截止日期">
	    <button onclick="upToVIP()" >确定</button>
	</div>
	
</body>

</html>